---@diagnostic disable: trailing-space
local extension = Package:new("moepack_moon")
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack_moon"] = "萌包-皎月",
}

local U = require "packages.utility.utility"
local MoeFunc = require "packages.moepack.moepack_function"







local moe__yezi = General(extension, "moe__yezi", "moe", 3, 3, General.Female)

local emo__luoai = fk.CreateTriggerSkill{
  name = "emo__luoai",
  anim_type = "drawcard",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target.phase > 1 and target.phase < 8 and #player.room.discard_pile > 0 then
      local n = 0
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile and move.moveReason ~= fk.ReasonUse and move.moveReason ~= fk.ReasonResonpse then
            n = n + #move.moveInfo
          end
        end
        return false
      end, Player.HistoryPhase)
      return n >= 2
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player, room.discard_pile[1], true, fk.ReasonPrey)
  end,
}

moe__yezi:addSkill(emo__luoai)

local emo__huahuo = fk.CreateActiveSkill{
  name = "emo__huahuo",
  anim_type = "drawcard",
  card_num = 1,
  min_target_num = 1,
  max_target_num = 3,
  target_filter = function(self, to_select, selected)
    return #selected < (3 - Self:getMark("emo__huahuo_used-phase"))
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 3 and player:getMark("emo__huahuo_used-phase") < 3
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    room:addPlayerMark(player, "emo__huahuo_used-phase")
    local card = Fk:getCardById(effect.cards[1])
    local cards = room:getCardsFromPileByRule(".|.|"..card:getSuitString(), #effect.tos)
    if #cards == 0 then return end
    room:moveCards({ ids = cards, toArea = Card.Processing, moveReason = fk.ReasonPut })
    local tos = table.map(effect.tos, Util.Id2PlayerMapper)
    table.forEach(room.players, function(p) room:fillAG(p, cards) end)
    for _, to in ipairs(tos) do
      if #cards == 0 then break end
      if to:isAlive() then
        local chosen = room:askForAG(to, cards, false, self.name)
        room:takeAG(to, chosen, room.players)
        room:obtainCard(to, chosen, true, fk.ReasonPrey)
        table.removeOne(cards, chosen)
      end
    end
    room:delay(1000)
    table.forEach(room.players, function(p) room:closeAG(p) end)

    local toDiscard = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if #toDiscard > 0 then
      room:moveCards({
        ids = toDiscard,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
      })
    end
  end,
}

moe__yezi:addSkill(emo__huahuo)


Fk:loadTranslationTable{
  ["moe__yezi"] = "叶子",

  ["emo__luoai"] = "落哀",
  [":emo__luoai"] = "任何阶段结束时，若此阶段内至少有两张牌不因使用或打出而进入弃牌堆，你可以获得最早进入弃牌堆的一张牌。",
  
  ["emo__huahuo"] = "花火",
  [":emo__huahuo"] = "出牌阶段限三次，你可以弃置一张牌并指定至多三名角色，亮出牌堆中等量张与你弃置的牌同花色的牌，你指定的角色依次挑选并获得其中一张牌，然后本阶段中此技能目标上限减1。",
}


local moe__shuizhilai = General(extension, "moe__shuizhilai", "moe", 3, 3, General.Female)

local emo__moyin = fk.CreateTriggerSkill{
  name = "emo__moyin",
  events = {fk.CardUseFinished, fk.CardRespondFinished, fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    local num
    if event == fk.AfterCardsMove then
      local ret = {}
      for _, move in ipairs(data) do
        if move.toArea == Card.PlayerHand and move.to == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.DrawPile then
              table.insert(ret, info.cardId)
            end
          end
        elseif move.from == player.id and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerEquip) or (info.fromArea == Card.PlayerHand) then
              table.insert(ret, info.cardId)
            end
          end
        end
      end
      if #ret ~= 1 then return false end
      num = Fk:getCardById(ret[1]).number
    elseif target == player then
      num = data.card.number
    end
    if num then
      self.cost_data = num
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("@emo__moyin")
    table.insert(mark, self.cost_data)
    if #mark > 3 then
      table.remove(mark, 1)
    end
    room:setPlayerMark(player, "@emo__moyin", mark)
    local max, min = math.max(table.unpack(mark)), math.min(table.unpack(mark))
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|0~"..(min-1)..","..(max+1).."~999",
      skipDrop = true,
    }
    room:judge(judge)
    if judge.card:matchPattern(judge.pattern) then
      if not player.dead and room:getCardArea(judge.card) == Card.Processing then
        room:obtainCard(player, judge.card, true, fk.ReasonPrey, player.id, self.name)
      end
    else
      if #room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#emo__moyin-discard") == 0 then
        room:invalidateSkill(player, self.name, "-turn")
      end
    end
    if room:getCardArea(judge.card) == Card.Processing then
      room:moveCardTo(judge.card, Card.DiscardPile, nil, fk.ReasonJudge)
    end
  end,

  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@emo__moyin", 0)
  end,
}
moe__shuizhilai:addSkill(emo__moyin)

local emo__chanlie = fk.CreateTriggerSkill{
  name = "emo__chanlie",
  anim_type = "masochism",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    local room = player.room
    local nums = player:getTableMark("@emo__moyin")
    room:setPlayerMark(player, "@emo__moyin", 0)
    local get = {}
    if #nums > 0 then
      local pile = table.simpleClone(room.discard_pile)
      while #nums > 0 do
        local id = table.remove(pile, math.random(#pile))
        if table.removeOne(nums, Fk:getCardById(id).number) then
          table.insert(get, id)
        end
      end
    end
    room:delay(200)
    if #get > 0 then
      room:moveCardTo(get, Player.Hand, player, fk.ReasonPrey, self.name, nil, true, player.id)
    else
      local cur = room.current
      if cur and cur:isAlive() then
        room:doIndicate(player.id, {cur.id})
        room:loseHp(cur, 1, self.name)
      end
    end
  end,
}
moe__shuizhilai:addSkill(emo__chanlie)

Fk:loadTranslationTable{
  ["emo__moyin"] = "魔音",
  [":emo__moyin"] = "锁定技，每当你使用、打出、摸、弃置一张牌后，你记录此牌点数，然后进行判定，若判定牌点数比最近三次点数记录均大或均小，你获得之，否则，你须弃置一张牌，或令本回合〖魔音〗失效。",
  ["@emo__moyin"] = "魔音",
  ["#emo__moyin-discard"] = "魔音：你须弃置一张牌，否则本回合〖魔音〗失效",

  ["emo__chanlie"] = "颤裂",
  [":emo__chanlie"] = "锁定技，当你受到伤害后，你清空“魔音”的记录，并从弃牌堆获得对应点数的牌各一张，若未获得牌，令当前回合者失去1点体力。",
}

local moe__zhuqukui = General(extension, "moe__zhuqukui", "moe", 3, 3, General.Female)

local emo__shenzhu = fk.CreateTriggerSkill{
  name = "emo__shenzhu",
  anim_type = "defensive",
  events = {fk.TurnEnd, fk.Damaged, fk.TurnStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnStart and player:getMark("@emo__blessing") <= player.hp then return false end
    return player == target and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      local n = player:getMark("@emo__blessing")
      room:setPlayerMark(player, "@emo__blessing", player.hp)
      room:recover { num = n - player.hp, skillName = self.name, who = player , recoverBy = player }
    else
      room:addPlayerMark(player, "@emo__blessing")
      player:drawCards(1, self.name)
      if not player.dead then
        room:changeMaxHp(player, 1)
      end
    end
  end,
}
moe__zhuqukui:addSkill(emo__shenzhu)


local emo__quchen = fk.CreateActiveSkill{
  name = "emo__quchen",
  anim_type = "support",
  can_use = function(self, player)
    return player.maxHp > player.hp
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  prompt = "#emo__quchen",
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local x = player.maxHp - to.maxHp
    room:changeMaxHp(player, -x)
    if not to.dead then
      to:drawCards(x, self.name)
      to:reset()
    end
  end,
}
moe__zhuqukui:addSkill(emo__quchen)

Fk:loadTranslationTable{
  ["moe__zhuqukui"] = "竹取葵",
  ["#moe__zhuqukui"] = "祭山巫女",
  
  ["emo__shenzhu"] = "神祝",
  [":emo__shenzhu"] = "锁定技，每当你受到伤害后或你回合结束时，你获得1枚“祝”标记，摸一张牌，增加1点体力上限。回合开始时，若你的“祝”标记大于体力值，你交换“祝”标记数与体力值。",
  ["@emo__blessing"] = "祝",

  ["emo__quchen"] = "祛尘",
  ["#emo__quchen"] = "将体力上限扣减至体力值，令一名其他角色摸等量张牌并复原武将牌",
  [":emo__quchen"] = "出牌阶段，你可以将体力上限扣减至体力值，令一名其他角色摸等量张牌并复原武将牌。",
}










local moe__lingnuoya = General(extension, "moe__lingnuoya", "moe", 4, 4, General.Female)

local emo__huazhu = fk.CreateTriggerSkill{
  name = "emo__huazhu",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, self.name)
    local pd_targets = table.filter(room:getOtherPlayers(player), function (p) return player:canPindian(p) end)
    if not player:isKongcheng() and #pd_targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(pd_targets, Util.IdMapper), 1, 2, "#emo__huazhu_pd", self.name, false)
      if #tos > 0 then
        tos = table.map(tos, Util.Id2PlayerMapper)
        local pindian = player:pindian(tos, self.name)
        local sum = 0
        local max_num = 0
        local damageTo
        for _, to in ipairs(tos) do
          local result = pindian.results[to.id]
          if result and result.toCard then
            local num = result.toCard.number
            sum = sum + num
            max_num = math.max(max_num, num)
            if num == max_num then
              damageTo = to
            end
            local winner = pindian.results[to.id].winner
            if winner == player and not player.dead then
              player:drawCards(1, self.name)
            end
          end
        end
        if sum > 10 and damageTo and not damageTo.dead then
          room:damage{ from = player, to = damageTo, damage = 1, skillName = self.name , damageType = fk.FireDamage }
        end
      end
    end
    local throw = room:askForDiscard(player, 2, 2, true, self.name, false, ".", "#emo__huazhu-discard")
    if #throw == 0 or player.dead then return false end

    local basic = #table.filter(throw, function (id) return Fk:getCardById(id).type == Card.TypeBasic end)
    if basic == 0 then
      room:addPlayerMark(player, "emo__huazhu_basic-phase")
    elseif basic == #throw then
      local slash = Fk:cloneCard("slash")
      local max_num = slash.skill:getMaxTargetNum(player, slash)
      local slash_targets = {}
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not player:isProhibited(p, slash) then
          table.insert(slash_targets, p.id)
        end
      end
      if #slash_targets > 0 and max_num > 0 then
        local tos = room:askForChoosePlayers(player, slash_targets, 1, max_num+1, "#emo__huazhu-slash", self.name, false)
        if #tos > 0 then
          room:useVirtualCard("slash", nil, player, table.map(tos, Util.Id2PlayerMapper), self.name, true)
        end
      end
    end
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("emo__huazhu_basic-phase") > 0 and data.card.type == Card.TypeBasic
  end,
  on_refresh = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
}

moe__lingnuoya:addSkill(emo__huazhu)


Fk:loadTranslationTable{
  ["moe__lingnuoya"] = "凌诺雅",

  ["emo__huazhu"] = "花主",
  [":emo__huazhu"] = "出牌阶段开始时，你可以摸两张牌，然后用一张手牌与一至两名其他角色同时拼点，你每赢一次便摸一张牌，若其他角色的拼点牌点数之和大于10，你对其中点数较大的一名角色造成1点火焰伤害。最后你弃置两张牌，若你弃置的牌均为：基本牌，你视为使用一张无距离限制、不计入次数且目标上限+1的【杀】；非基本牌，本阶段你使用基本牌额外结算一次。",
  ["emo__huazhu_pd"] = "花主",
  ["#emo__huazhu_pd"] = "花主：用一张手牌与一至两名其他角色同时拼点，每赢一次便摸一张牌",
  ["#emo__huazhu-slash"] = "花主：你视为使用一张无距离限制、不计入次数且目标上限+1的【杀】",
  ["#emo__huazhu-discard"] = "花主：弃置两张牌，若均为基本牌或非基本牌，执行额外效果",
}


local moe__xifu = General(extension, "moe__xifu", "moe", 4, 4, General.Female)

local emo__ciren = fk.CreateTriggerSkill{
  name = "emo__ciren",
  events = {fk.EventPhaseStart},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Start then
      return table.find(player:getCardIds("he"), function (id) return Fk:getCardById(id).trueName == "mithril_dagger" end) == nil
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardId = MoeFunc.getDerivedCard(room, "mithril_dagger")
    if cardId == nil then return false end
    local from = room:getCardOwner(cardId)
    room:obtainCard(player, cardId, true, fk.ReasonPrey, player.id, self.name)
    if not player.dead and table.contains(player:getCardIds("h"), cardId) then
      Fk:filterCard(cardId, player)
      local card = Fk:getCardById(cardId)
      if card.name == "mithril_dagger" and player:canUseTo(card, player) then
        room:useCard{from = player.id, tos = {{player.id}}, card = card}
      end
    end
    if from and not from.dead and not player.dead and from ~= player
    and room:askForSkillInvoke(player, self.name, nil, "#emo__ciren-draw:"..from.id) then
      room:doIndicate(player.id, {from.id})
      from:drawCards(2, self.name)
    end
  end,
}
moe__xifu:addSkill(emo__ciren)

local emo__xunzhan = fk.CreateTriggerSkill{
  name = "emo__xunzhan",
  events = {fk.EventPhaseStart},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self) and target.phase == Player.Play and not target.dead then
      return (not target:isKongcheng()) or (not player:isNude())
    end
  end,
  on_cost = function (self, event, target, player, data)
    local _,dat = player.room:askForUseActiveSkill(player, "emo__xunzhan_active", "#emo__xunzhan-ask:"..target.id,
    true, {emo__xunzhan_to = target.id})
    if dat then
      self.cost_data = {choice = dat.interaction, tos = {target.id}, cards = dat.cards}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardId
    if self.cost_data.choice == "emo__xunzhan_throw" then
      cardId = room:askForCardChosen(player, target, "h", self.name)
      room:throwCard(cardId, self.name, target, player)
    else
      cardId = self.cost_data.cards[1]
      room:useVirtualCard("slash", self.cost_data.cards, player, target, self.name, true)
    end
    local inhand = table.contains(target:getCardIds("h"), cardId)
    if not target.dead and (room:getCardArea(cardId) == Card.DiscardPile or inhand) then
      if inhand then
        Fk:filterCard(cardId, target)
      end
      local card = Fk:getCardById(cardId)
      if card.type == Card.TypeEquip then
        if target:getAvailableEquipSlots(card.sub_type) and not target:prohibitUse(card) then
          room:useCard{from = target.id, tos = {{target.id}}, card = card}
        end
      elseif card.trueName == "slash" then
        local extra_data = {extraUse = false}
        if not inhand then
          extra_data.expand_pile = {cardId}
        end
        U.askForUseRealCard(room, target, {cardId}, ".", self.name, "#emo__xunzhan_slash", extra_data, false, false)
      end
    end
  end,
}

local emo__xunzhan_active = fk.CreateActiveSkill{
  name = "emo__xunzhan_active",
  card_num = 1,
  target_num = 0,
  interaction = function(self)
    local all_choices = {"emo__xunzhan_throw", "emo__xunzhan_slash"}
    local choices = {}
    local to = Fk:currentRoom():getPlayerById(self.emo__xunzhan_to)
    if to and not to:isKongcheng() then
      table.insert(choices, "emo__xunzhan_throw")
    end
    if not Self:isNude() then
      table.insert(choices, "emo__xunzhan_slash")
    end
    return UI.ComboBox { choices = choices, all_choices = all_choices }
  end,
  card_filter = function(self, to_select, selected)
    local choice = self.interaction.data
    if choice == "emo__xunzhan_slash" then
      if #selected ~= 0 then return false end
      local to = Fk:currentRoom():getPlayerById(self.emo__xunzhan_to)
      if not to then return false end
      local c = Fk:cloneCard("slash")
      c.skillName = "emo__xunzhan"
      c:addSubcard(to_select)
      return Self:canUseTo(c, to, {bypass_distances = true, bypass_times = true})
    elseif choice == "emo__xunzhan_throw" then
      return false
    end
  end,
  feasible = function (self, selected, selected_cards)
    local choice = self.interaction.data
    if choice == "emo__xunzhan_slash" then
      return #selected_cards == 1
    elseif choice == "emo__xunzhan_throw" then
      return #selected_cards == 0
    end
  end,
}
Fk:addSkill(emo__xunzhan_active)

moe__xifu:addSkill(emo__xunzhan)

Fk:loadTranslationTable{
  ["moe__xifu"] = "希芙",
  ["#moe__xifu"] = "圣殉者",

  ["emo__ciren"] = "赐刃",
  [":emo__ciren"] = "准备阶段，若你没有【秘银短匕】，你获得并使用之，若你从其他角色区域内获得，你可以令其摸两张牌。",
  ["#emo__ciren-draw"] = "赐刃：你可以令 %src 摸两张牌",

  ["emo__xunzhan"] = "殉战",
  [":emo__xunzhan"] = "其他角色的出牌阶段开始时，你可以弃置其一张手牌，或将一张牌当【杀】对其使用，然后若此牌为装备牌或【杀】，令其使用之。",
  ["#emo__xunzhan-ask"] = "殉战：你可以弃置 %src 的手牌，或将一张牌当【杀】对其使用",
  ["emo__xunzhan_throw"] = "弃置其手牌",
  ["emo__xunzhan_slash"] = "一张牌当【杀】",
  ["emo__xunzhan_active"] = "殉战",
  ["#emo__xunzhan_slash"] = "殉战：你须使用这张【杀】！",
}

local emo__lingfeng = fk.CreateTriggerSkill{
  name = "emo__lingfeng",
  anim_type = "control",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    local currentEvent = player.room.logic:getCurrentEvent()
    local turnEvent = currentEvent:findParent(GameEvent.Turn)
    local suitCheck = function (suit)
      if turnEvent == nil then return false end
      return #player.room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
        if e.id >= currentEvent.id then return false end
        for _, move in ipairs(e.data) do
          if (move.toArea == Card.DiscardPile or move.toArea == Card.Processing) then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId):getSuitString() == suit then
                return true
              end
            end
          end
        end
      end, turnEvent.id) == 0
    end
    local suits = {}
    for _, move in ipairs(data) do
      if move.from == player.id and (move.toArea == Card.DiscardPile or move.toArea == Card.Processing) then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            table.insert(suits, Fk:getCardById(info.cardId):getSuitString())
          end
        end
      end
    end
    if #suits == 0 then return false end
    suits = table.filter(suits, suitCheck)
    if #suits > 0 then
      self.cost_data = suits
      return true
    end
  end,
  on_trigger = function (self, event, target, player, data)
    local suits = table.simpleClone(self.cost_data)
    for _, suit in ipairs(suits) do
      if not player:hasSkill(self) then return end
      self:doCost(event, player, player, suit)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
     "#emo__lingfeng-choose:::log_"..data, self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos, suit = data}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local suit = self.cost_data.suit
    local ids = room:getCardsFromPileByRule(".|.|"..suit)
    if #ids > 0 then
      room:obtainCard(to, ids, true, fk.ReasonJustMove, player.id, self.name)
    end
  end,
}

Fk:loadTranslationTable{
  ["emo__lingfeng"] = "聆风",
  [":emo__lingfeng"] = "每当你失去一张牌时，若此花色的牌本回合首次进入处理区或弃牌堆，你可令一名角色从牌堆随机获得一张此花色的牌。",
  ["#emo__lingfeng-choose"] = "聆风：你可令一名角色从牌堆随机获得一张 %arg 牌",
}

local moe__victoria = General(extension, "moe__victoria", "moe", 3, 3, General.Female)

local emo__lianshang = fk.CreateTriggerSkill{
  name = "emo__lianshang",
  anim_type = "control",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target and (not target.dead) and player:hasSkill(self) and (not player:isKongcheng()) and data.from
    and data.from ~= player and (not data.from.dead) and player:canPindian(data.from)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__lianshang-invoke:"..data.from.id..":"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pindian = player:pindian({data.from}, self.name)
    local winner = pindian.results[data.from.id].winner
    if winner and winner == player then
      if not target.dead and target:isWounded() then
        room:recover { num = 1, skillName = self.name, who = target, recoverBy = player}
      end
    else
      local ids = {}
      for _, card in ipairs({pindian.fromCard, pindian.results[data.from.id].toCard}) do
        if room:getCardArea(card) == Card.DiscardPile then
          table.insertIfNeed(ids, card:getEffectiveId())
        end
      end
      if #ids > 0 and not player.dead then
        room:moveCards({
          ids = ids,
          to = target.id,
          toArea = Player.Hand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
    if not (data.card and data.card.trueName == "slash") and not player.dead then
      player:drawCards(1, self.name)
    end
  end,
}
moe__victoria:addSkill(emo__lianshang)

local emo__jieli = fk.CreateActiveSkill{
  name = "emo__jieli",
  anim_type = "support",
  prompt = "#emo__jieli-prompt",
  can_use = function(self, player)
    return player:getMark("emo__jieli-phase") == 0 and
    player:usedSkillTimes(self.name, Player.HistoryPhase) < #Fk:currentRoom().alive_players
  end,
  card_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "slash"
  end,
  target_num = 1,
  target_filter = function(self, to_select, selected, cards)
    return #selected == 0 and to_select ~= Self.id and #cards == 1
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:recastCard(effect.cards, player, self.name)
    local to = room:getPlayerById(effect.tos[1])
    if player.dead then return end
    if to.dead or to:isNude() then
      room:addPlayerMark(player, "emo__jieli-phase")
      return
    end
    local cards = room:askForCard(to, 1, 1, false, self.name, true, "slash", "#emo__jieli-discard:"..player.id)
    if #cards > 0 then
      room:recastCard(cards, player, self.name)
      if not player.dead then
        player:drawCards(1, self.name)
      end
      if not to.dead then
        to:drawCards(1, self.name)
      end
    else
      room:addPlayerMark(player, "emo__jieli-phase")
      local cid = room:askForCardChosen(player, to, "he", self.name)
      room:moveCardTo(cid, Player.Hand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    end
  end,
}
moe__victoria:addSkill(emo__jieli)

local emo__anqin = fk.CreateMaxCardsSkill{
  name = "emo__anqin$",
  exclude_from = function(self, player, card)
    if card and (card.trueName == "jink" or card.trueName == "peach") then
      if player.kingdom == "moe" then
        for _, lord in ipairs(Fk:currentRoom().alive_players) do
          if lord:hasSkill(self) and lord.role == "lord" and table.find(Fk:currentRoom().alive_players, function(p) return p ~= lord and p.kingdom == "moe" end) then
            return true
          end
        end
      end
    end
  end,
}
moe__victoria:addSkill(emo__anqin)

Fk:loadTranslationTable{
  ["moe__victoria"] = "维多利亚",

  ["emo__lianshang"] = "怜伤",
  [":emo__lianshang"] = "一名角色受到伤害后，若其仍存活，你可以与伤害来源拼点：若你赢，你令该角色回复1点体力；若你没赢，该角色获得两张拼点牌。若不为【杀】造成的伤害，你摸一张牌。",
  ["#emo__lianshang-invoke"] = "怜伤：你可与 %src 拼点：若你赢，你令 %dest 回复1点体力；若你没赢，%dest 获得两张拼点牌",

  ["emo__jieli"] = "戒戾",
  [":emo__jieli"] = "出牌阶段限X次，你可以重铸一张【杀】并令一名其他角色选一项：1.重铸一张【杀】，与你各摸一张牌；2.你获得其一张牌，此阶段〖戒戾〗无效（X为存活角色数）。",
  ["#emo__jieli-discard"] = "戒戾:1.重铸一张【杀】，与 %src 各摸一张牌；2.%src 获得你一张牌",
  ["#emo__jieli-prompt"] = "戒戾:重铸一张【杀】并选择一名其他角色",

  ["emo__anqin"] = "安寝",
  [":emo__anqin"] = "主公技，锁定技，若其他萌势力角色存活，你与其的【闪】和【桃】不计入手牌上限。",
}




--[[
local moe__yeling = General(extension, "moe__yeling", "moe", 3, 3, General.Female)

local emo__xuewu = fk.CreateActiveSkill{
  name = "emo__xuewu",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  prompt = "#emo__xuewu-prompt",
  can_use = function(self, player)
    return player:getMark("emo__xuewu_fail-phase") == 0 and player:canUse(Fk:cloneCard("slash"))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = {}
    for i, id in ipairs(room.draw_pile) do
      if i > 3 then break end
      if Fk:getCardById(id).trueName == "slash" then
        table.insert(cards, id)
      end
    end
    for _, p in ipairs(room:getOtherPlayers(player)) do
      for _, id in ipairs(p:getCardIds("h")) do
        if Fk:getCardById(id).trueName == "slash" then
          table.insert(cards, id)
        end
      end
    end
    if #cards > 0 then
      local cid = table.random(cards)
      local owner = room.owner_map[cid]
      local from = owner and room:getPlayerById(owner) or player
      from:showCards({cid})
      local slash = Fk:getCardById(cid)
      local max_num = slash.skill:getMaxTargetNum(player, slash)
      local targets = table.filter(room.alive_players, function (p)
        return player:canUseTo(slash, p)
      end)
      if max_num > 0 and #targets > 0 then
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
        "#emo__xuewu-choose:::"..slash:toLogString(), self.name, false)
        room:useCard{
          from = player.id,
          tos = table.map(tos, function(p) return {p} end),
          card = slash,
          extra_data = {emo__xuewu_from = owner or 0}
        }
        return nil
      end
    end
    room:setPlayerMark(player, "emo__xuewu_fail-phase", 1)
  end,
}

local emo__xuewu_trigger = fk.CreateTriggerSkill{
  name = "#emo__xuewu_trigger",
  -- 用于修改杀的伤害来源
  refresh_events = {fk.PreDamage},
  can_refresh = function(self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if e then
      return (e.data[1].extra_data or {}).emo__xuewu_from
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if e then
      local owner = e.data[1].extra_data.emo__xuewu_from
      if owner == 0 then
        data.from = nil
      else
        data.from = room:getPlayerById(owner)
      end
    end
  end,
}
emo__xuewu:addRelatedSkill(emo__xuewu_trigger)
moe__yeling:addSkill(emo__xuewu)

local emo__shayu = fk.CreateTriggerSkill{
  name = "emo__shayu",
  anim_type = "defensive",
  events = {fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isNude() and player.phase == Player.NotActive
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForDiscard(player, 1, #player:getCardIds("he"), true, self.name, true, ".", "#emo__shayu-card", true)
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data
    local add = (not data.card) or table.every(cards, function (id)
      return Fk:getCardById(id).color ~= data.card.color
    end)
    room:throwCard(cards, self.name, player, player)
    if player.dead then return end
    player:drawCards(#cards + 1, self.name)
    if player.dead then return end
    if add then
      room:addPlayerMark(player, "@emo__shayu")
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@emo__shayu") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@emo__shayu", 0)
  end,
}
local emo__shayu_targetmod = fk.CreateTargetModSkill{
  name = "#emo__shayu_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return player:getMark("@emo__shayu")
    end
  end,
}
emo__shayu:addRelatedSkill(emo__shayu_targetmod)
moe__yeling:addSkill(emo__shayu)

Fk:loadTranslationTable{
  ["emo__xuewu"] = "血舞",
  [":emo__xuewu"] = "出牌阶段，若你可以使用【杀】，你可以发动此技能：若其他角色手牌中或牌堆顶三张牌中有【杀】，你随机展示其中一张【杀】并使用之（此【杀】造成的伤害来源视为拥有此【杀】的角色，若为牌堆的【杀】视为无伤害来源），若这些牌中没有【杀】或你未使用之，本技能于此阶段失效。",
  ["#emo__xuewu_trigger"] = "血舞",
  ["#emo__xuewu-choose"] = "血舞：请选择你使用%arg的目标",
  ["#emo__xuewu-prompt"] = "血舞：若其他角色手牌中或牌堆顶三张牌中有【杀】，你可使用之，若无，本技能此阶段失效",

  ["emo__shayu"] = "铩羽",
  [":emo__shayu"] = "每当你于回合外受到伤害后，你可以弃置至少一张牌，摸X张牌（X为弃置牌数+1），若没有造成伤害的牌，或造成伤害的牌与你弃置的牌颜色均不同，你使用【杀】次数上限+1直到你下回合结束。",
  ["#emo__shayu-card"] = "铩羽：弃置至少一张牌，摸等量+1张牌",
  ["@emo__shayu"] = "铩羽",
}

local moe__dianna = General(extension, "moe__dianna", "moe", 4, 4, General.Female)

local emo__gongshou = fk.CreateTriggerSkill{
  name = "emo__gongshou",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and player.phase == Player.Start then
      return table.every(player.room.alive_players, function(p) return p:getMark("@@emo__gongshou") == 0 end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__gongshou-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    room:setPlayerMark(to, "@@emo__gongshou", 1)
  end,
}
local emo__gongshou_attackrange = fk.CreateAttackRangeSkill{
  name = "#emo__gongshou_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("emo__gongshou") then
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if p:getMark("@@emo__gongshou") > 0 then
          local weapon = p:getEquipment(Card.SubtypeWeapon)
          if weapon then
            return Fk:getCardById(weapon).attack_range or 0
          end
        end
      end
    end
  end,
}
emo__gongshou:addRelatedSkill(emo__gongshou_attackrange)

moe__dianna:addSkill(emo__gongshou)


local emo__youtian = fk.CreateActiveSkill{
  name = "emo__youtian",
  anim_type = "offensive",
  card_filter = Util.FalseFunc,
  prompt = "#emo__youtian-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < #Fk:currentRoom().alive_players and player:getAttackRange() > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.filter(room.alive_players, function(p) return player:inMyAttackRange(p) end)
    player:drawCards(1, self.name)
    room:addPlayerMark(player, "emo__youtian-phase", 1)
    if player.dead then return end
    targets = table.filter(targets, function (p) return not player:inMyAttackRange(p) end)
    if #targets > 0 then
      local use = room:askForUseCard(player, "slash", "slash", "#emo__youtian-slash", true,
      {exclusive_targets = table.map(targets, Util.IdMapper) , bypass_distances = true })
      if use then
        use.extraUse = true
        room:useCard(use)
      end
    end
  end,
}
local emo__youtian_attackrange = fk.CreateAttackRangeSkill{
  name = "#emo__youtian_attackrange",
  correct_func = function (self, from, to)
    return - from:getMark("emo__youtian-phase")
  end,
}
emo__gongshou:addRelatedSkill(emo__youtian_attackrange)

moe__dianna:addSkill(emo__youtian)

Fk:loadTranslationTable{
  ["moe__dianna"] = "狄安娜",

  ["emo__gongshou"] = "共狩",
  [":emo__gongshou"] = "准备阶段开始时，若没有角色拥有“狩”标记，你可以令一名其他角色获得“狩”标记，你的攻击范围+X（X为该角色装备区武器牌的攻击范围）。",
  ["@@emo__gongshou"] = "狩",
  ["#emo__gongshou-choose"] = "共狩：令一名其他角色获得“狩”标记，你获得其武器的攻击范围",

  ["emo__youtian"] = "游畋",
  [":emo__youtian"] = "出牌阶段限X次，若你攻击范围大于0，你可以摸一张牌并令本阶段攻击范围-1，若有角色因此脱离你的攻击范围，你可以对其中一名角色使用一张不计入次数的【杀】（X为存活角色数）。",
  ["#emo__youtian-slash"] = "游畋：你可以对其中一名角色使用【杀】",
  ["#emo__youtian-prompt"] = "游畋：你可以摸一张牌并令本阶段攻击范围-1",
}

--]]







return extension

